package org.viettan.android.main.managers;

import java.util.List;

import org.viettan.android.main.io.EntityRetrievalException;
import org.viettan.android.main.io.NetworkUtility;
import org.viettan.android.main.io.UrlUtility;
import org.viettan.android.main.model.Section;
import org.viettan.android.main.xml.SectionXmlParser;

import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
 * Singleton to manage retrieving the sections from the Viet Tan website feed.
 */
@Singleton
public class SectionManager extends BaseEntityManager<Section> {

    @Inject
    private final UrlUtility urlUtility;

    @Inject
    SectionManager(UrlUtility urlUtility, NetworkUtility networkUtility,
	    SectionXmlParser sectionXmlParser) {
	super(networkUtility, sectionXmlParser);
	this.urlUtility = urlUtility;
    }

    /**
     * Returns the complete list of {@link Section}s.
     *
     * @param useCache
     *            retrieve the data from the cache if it is there
     * @return List of {@link Section}
     * @throws EntityRetrievalException
     */
    public List<Section> getSections(boolean useCache) throws EntityRetrievalException {
	return getEntities(urlUtility.getSectionsFeed(), useCache);
    }
}
